package control;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.login.LoginService;
import model.vo.MemberVO;
import model.vo.WorkorderVO;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class LoginContoller extends MultiActionController{
	private LoginService loginService;
	private MachineController mc;
	public void setmachineController(MachineController mc) {
		this.mc = mc;
		
	}
	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
	
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response,
			MemberVO mvo){
		try {
			String member_id=loginService.loginCheck(mvo);
			mvo.setMember_password(null);
			//System.out.println(member_id+"컨트롤러에서 id확인");
			if(member_id!=null){
				loginService.loginHistoryWrite(mvo);
			}else{
				mvo.setMember_id(null);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		//System.out.println(mvo);
		return new ModelAndView("JsonView","mvo",mvo);
	}
	
	public ModelAndView logout(HttpServletRequest request, HttpServletResponse response){
		HttpSession session=request.getSession();
		session.invalidate();
		return new ModelAndView("JsonView","logout",null);
	}
	public ModelAndView production_stateView(HttpServletRequest request,
			HttpServletResponse response) throws SQLException{
		String production_state = mc.production_stateView();
		return new ModelAndView("JsonView","production_state",production_state);
	}	
	// 운영자 지시사항을 확인시,
		public ModelAndView workorderCheck(HttpServletRequest request,
				HttpServletResponse response) throws SQLException{
			WorkorderVO wvo = mc.workorderCheck();
			//System.out.println(wvo+"11111111");
			return new ModelAndView("JsonView","wvo",wvo);
		}
	
}
